<template>
  <div class="home">
    <el-container>
      <el-aside width="auto">
        <div class="logo"></div>
        <el-menu
          class="el-menu-vertical-demo"
          router
          unique-opened
          :collapse="iscollapse"
          background-color="#F9F9F9"
          @open="handleOpen"
          @close="handleClose"
        >
          <el-submenu :index="menu.path" v-for="menu in menuList" :key="menu.id">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>{{menu.authName}}</span>
            </template>
            <el-menu-item :index="submenu.path" v-for="submenu in menu.children" :key="submenu.id">
              <i class="el-icon-tickets"></i>
              <span>{{submenu.authName}}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <div class="toggle-btn" @click="toggle">
            <i class="myicon myicon-menu"></i>
          </div>
          <div class="system-title">电商后台管理系统</div>
          <div>
            <span class="welcome">您好，{{username}}</span>
            <el-button type="warning" round @click="loginout">退出</el-button>
          </div>
        </el-header>
        <el-main>
          <transition
            enter-active-class="animated fadeIn"
            leave-active-class="animated fadeOut"
            mode="out-in"
          >
            <router-view></router-view>
          </transition>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>


<script>
import {menus} from '@/api'
export default {
  created() {
    this.username = localStorage.getItem("username");
    this.getmenus()
  },
  data() {
    return {
      iscollapse: true,
      username: "",
      menuList:[]
    };
  },
  methods: {
    handleOpen(key, keyPath) {},
    handleClose(key, keyPath) {},
    toggle() {
      this.iscollapse = !this.iscollapse;
    },
    loginout() {
      localStorage.clear();
      this.$router.push({ name: "login" });
    },
    getmenus(){
      menus()
      .then(res=>{
        this.menuList=res.data.data
      })
    }
  }
};
</script>


<style lang="scss" scoped>
.home {
  height: 100%;
  .el-menu-admin:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
  .el-container {
    height: 100%;
  }
  .el-aside {
    background-color: #f9f9f9;
  }
  .el-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #409eff;
  }
  .logo {
    height: 60px;
    background: url(../assets/logo.png);
    background-size: cover;
    background-color: white;
  }
  .toggle-btn {
    padding: 0 15px;
    margin-left: -20px;
    font-size: 36px;
    color: white;
    cursor: pointer;
    line-height: 60px;
    &:hover {
      background-color: #4292cf;
    }
  }
  .system-title {
    font-size: 28px;
    color: white;
  }
  .welcome {
    color: white;
  }
}
</style>